#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
#include <unistd.h>
#include <time.h>

typedef struct input_event input;


/**
 *
 * /*
 * Event types


#define EV_SYN			0x00
#define EV_KEY			0x01
#define EV_REL			0x02
#define EV_ABS			0x03
#define EV_MSC			0x04
#define EV_SW			0x05
#define EV_LED			0x11
#define EV_SND			0x12
#define EV_REP			0x14
#define EV_FF			0x15
#define EV_PWR			0x16
#define EV_FF_STATUS		0x17
#define EV_MAX			0x1f
#define EV_CNT			(EV_MAX+1)


 */

#define MY_EVENT "/dev/input/event4"

int main() {
	int fd = -1;
	int ret = -1;

	struct input_event ev = { 0 };
	const int size = sizeof(input);

	fd = open(MY_EVENT, O_RDONLY);
	if (fd < 0) {
		perror("open");
		return -1;
	}
	while (1) {
		ret = read(fd, &ev, size);
		if (ret != size) {
			close(fd);
			return -1;
		}
		printf("type = %x, code = %x, value = %x\n", ev.type, ev.code,
				ev.value);

		struct tm t;
		char date_time[64] = { 0 };
		strftime(date_time, sizeof(date_time), "%Y-%m-%d %H:%M:%S",
				localtime_r(&ev.time.tv_sec, &t));
		printf("gettimeofday: date_time = %s\n", date_time);

	}
	close(fd);
}

